package com.slothought.rowgazer

import grails.test.*

class ParamExtractorTests extends GrailsUnitTestCase  {
    protected void setUp() {
        super.setUp()
    }
    
    protected void tearDown() {
        super.tearDown()
    }
    
    void testParsingParams() {
        def paramTest = { def mapper, def params, def em ->
            
            try {  mapper = new ParamsExtractor(params)  ; "ok"}
            catch(Exception e){
                e.getMessage()  
            }
        }
        
        def mapper 
        Map params 
        String errmsg = ""
        
        
        
        params = ['d13.v0':'1235', 'd13.v1':'1235',  'd115.v0':'1235', 'd115.v1':'1235', '1234':'d123.v3', 'c0':'field', 'c1':'field']
        errmsg = null
        assert paramTest( mapper, params, errmsg) == "ok"
        
        params = ['d13.v0':'1235', 'd13.v1':'1235',  'd115.v0':'1235', 'd115.v2':'1235', 'd115.v1':'1235','1234':'d123.v3', 'c0':'field', 'c1':'field']
        errmsg = null
        assert paramTest( mapper, params, errmsg) == "filter value indexes not in the form of [0..n]"
        
        params = ['d13.v0':'1235', 'd13.v1':'1235',  'd115.v0':'1235', 'd115.v1':'1235', 'd115.v':'1235','1234':'d123.v3', 'c0':'field', 'c1':'field']
        errmsg = null
        assert paramTest( mapper, params, errmsg) == "ok"
        
        params = ['d13.v4':'1235', 'd115.v3':'1235', '1234':'d123.v3', 'c0':'sfja']
        errmsg = null
        assert paramTest( mapper, params, errmsg) == "filter value indexes not in the form of [0..n]"
        params = ['d13.v0':'1235', 'd13.v1':'1235',  'd115.v0':'1235', 'd115.v1':'1235', '1234':'d123.v3', 'c1':'field']
        errmsg = null
        assert paramTest( mapper, params, errmsg) == "column indexes not in the form or [0..n]"
    }
}